package org.burning.crm.workbench.web.controller;

import org.burning.crm.commons.constants.Constant;
import org.burning.crm.commons.domain.ReturnObject;
import org.burning.crm.workbench.domain.*;
import org.burning.crm.workbench.service.TranService;
import org.burning.crm.workbench.service.impl.AiManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
public class ChatController {
    @Autowired
    private TranService tranService;

    @Resource
    private AiManager aiManager;

    //交易图表
    @RequestMapping("/workbench/chart/transaction/index.do")
    public String index() {
        //跳转页面
        return "workbench/chart/transaction/index";
    }

//客户和联系人统计图表
    @RequestMapping("/workbench/chart/customerAndContacts/contact.do")
    public String contact() {
        //跳转页面
        return "workbench/chart/customerAndContacts/contact";
    }

    //线索统计图表
    @RequestMapping("/workbench/chart/transaction/clue.do")
    public String clue() {
        //跳转页面
        return "workbench/chart/transaction/clue";
    }

    //市场统计图表
    @RequestMapping("/workbench/chart/transaction/market.do")
    public String market() {
        //跳转页面
        return "workbench/chart/transaction/market";
    }

    @RequestMapping("/workbench/chart/transaction/queryCountOfTranGroupByStage.do")
    public @ResponseBody
    Object queryCountOfTranGroupByStage() {
        //查询漏斗图所需的数据集合
        List<FunnelVO> funnelVOList = tranService.queryCountOfTranGroupByStage();

        return funnelVOList;
    }

    @RequestMapping("/workbench/chart/customerAndContacts/queryCountOfTranGroupByStage1.do")
    public @ResponseBody
    Object queryCountOfTranGroupByStage1() {
        //查询饼图图所需的数据集合
        List<Pie> funnelVOList = tranService.queryCountOfTranGroupByStage1();
        System.out.println(funnelVOList);
        return funnelVOList;
    }

    @RequestMapping("/workbench/chart/transaction/queryCountOfTranGroupByStage2.do")
    public @ResponseBody
    Object queryCountOfTranGroupByStage2() {
        //查询柱状图所需的数据集合
        List<Bar> funnelVOList = tranService.queryCountOfTranGroupByStage2();
        System.out.println(funnelVOList);
        return funnelVOList;
    }

//    @RequestMapping("/workbench/chart/transaction/queryCountOfTranGroupByStage3.do")
//    public @ResponseBody
//    Object queryCountOfTranGroupByStage3() {
//        //查询折线图所需的数据集合
//        List<Line> funnelVOList = tranService.queryCountOfTranGroupByStage3();
//        System.out.println(funnelVOList);
//        return funnelVOList;
//    }

    /**
     * 市场活动信息统计
     * @return 保存统计信息的响应结果对象
     * retData结构示例：
     * [
     *   {"市场活动名称": "活动A", "关联的联系人数量": 50, "关联的线索数量": 20},
     *   {"市场活动名称": "活动B", "关联的联系人数量": 30, "关联的线索数量": 15}
     * ]
     */
    @RequestMapping("/getActivityChart")
    @ResponseBody
    public Object getActivityChart() {
        ReturnObject returnObject = new ReturnObject();

        List<Map<String, Object>> result = tranService.getActivityChart();

        if (result.size() > 0) {
            returnObject.setCode(Constant.RETURN_OBJECT_CODE_SUCCESS);
            returnObject.setMessage("success");
            returnObject.setRetData(result);
        } else {
            returnObject.setCode(Constant.RETURN_OBJECT_CODE_FAIL);
            returnObject.setMessage("fail");
        }

        return returnObject;
    }

}
